//
//  GTSearchGiftCell.m
//  GiftTalk
//
//  Created by Wan on 16/3/28.
//  Copyright © 2016年 Wan. All rights reserved.
//  搜索结果，礼物展示cell

#import "GTSearchGiftCell.h"
#import "GTSearchGift.h"
#import <UIImageView+WebCache.h>

static NSString * const reuseIdentifier = @"searchGiftCell";

@interface GTSearchGiftCell()
@property (weak, nonatomic) IBOutlet UIImageView *giftImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *favoriteView;
@end


@implementation GTSearchGiftCell

- (void)awakeFromNib {
    // Initialization code
    
    [self.nameLabel sizeToFit];
    self.backgroundColor = [UIColor whiteColor];
}

/**
 *  创建搜索结果列表，可重用的 collectionViewCell
 */
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath
{
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(self) bundle:nil] forCellWithReuseIdentifier: reuseIdentifier];
    
    GTSearchGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    return cell;
}

- (void)setGift:(GTSearchGift *)gift
{
    [self.giftImage sd_setImageWithURL:[NSURL URLWithString:gift.cover_image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.nameLabel.text = gift.name;
    self.priceLabel.text = [NSString stringWithFormat:@"￥ %@",gift.price];
    [self.favoriteView setTitle:gift.favorites_count forState:UIControlStateNormal];
}

@end
